package com.example.mybatis.service.impl;

import com.example.mybatis.dao.UserMapper;
import com.example.mybatis.model.User;
import com.example.mybatis.model.UserExample;
import com.example.mybatis.service.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public User getUserById(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> listUser(int page, int pageSize) {
        List<User> result = null;
//        UserExample userExample = new UserExample();
        try {
            PageHelper.startPage(page, pageSize);
            PageHelper.orderBy("id ASC");
            result = userMapper.selectByExample(new UserExample());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
